﻿<UserControl x:Class="VSTalk.Engine.View.AccountEditorControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:utils="clr-namespace:VSTalk.Engine.Utils">
  <UserControl.Resources>
    <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="..\Resources\Icons.xaml" />
      </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
  </UserControl.Resources>
  <Grid>
    <Grid.Resources>
      <utils:ElementSpy x:Key="EditorSpy" />
      <VisualBrush x:Key="EditIcon" Stretch="Fill" Visual="{StaticResource appbar_edit}"/>
        <!--<ContextMenu x:Key="RowMenu">
            <MenuItem Command="{Binding Path=DataContext.EditClient, Source={x:Reference AccountsEditorGrid}}" Header="Edit" Padding="0" Margin="0"/>
        </ContextMenu>-->
        </Grid.Resources>
    <Grid.RowDefinitions>
      <RowDefinition />
      <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <DataGrid CanUserAddRows="False"
              CanUserDeleteRows="False"
              CanUserResizeColumns="True"
              CanUserResizeRows="False"
              CanUserReorderColumns="True"
              SelectionMode="Single"
              AutoGenerateColumns="False"
              SelectionUnit="FullRow"
              ItemsSource="{Binding Clients}"
              SelectedItem="{Binding SelectedClient}"
              x:Name="AccountsEditorGrid">
      <DataGrid.Columns>
        <DataGridTextColumn Header="Name"
                            Width="2*"
                            Binding="{Binding Login}"
                            IsReadOnly="True" />
        <DataGridTextColumn Header="Server"
                            Width="*"
                            Binding="{Binding Server}"
                            IsReadOnly="True" />
        <DataGridTemplateColumn>
          <DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
              <Button Command="{Binding Element.DataContext.EditClient, Source={StaticResource EditorSpy}}"
                      CommandParameter="{Binding .}">
                <Rectangle Width="14" Height="16" Fill="{StaticResource EditIcon}"/>
              </Button>
            </DataTemplate>
          </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
      </DataGrid.Columns>
            <DataGrid.RowStyle>
                <Style TargetType="DataGridRow">
                    <!--<Setter Property="ContextMenu" Value="{StaticResource RowMenu}"/>-->
                    <Setter Property="IsEnabled" Value="True"/>
                    <Style.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="Background" Value="DeepSkyBlue"/>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </DataGrid.RowStyle>
        </DataGrid>
    <StackPanel Grid.Row="1"
                HorizontalAlignment="Right"
                Orientation="Horizontal">
      <Button Margin="5"
              Padding="5"
              Content="Add"
              Command="{Binding AddNewClient}" />
      <Button Margin="5"
              Padding="5"
              Content="Delete"
              Command="{Binding RemoveClient}" />
    </StackPanel>
  </Grid>

</UserControl>
